/* 
 * File:   BvhNode.h
 * Author: matt
 *
 * Created on March 4, 2011, 6:21 PM
 */

#ifndef BVHNODE_H
#define	BVHNODE_H

#include "Surface.h"

class BvhNode : public Surface {
private:
    Surface* left;
    Surface* right;
    Box combine(Box, Box);
    Box bbox;

public:
    BvhNode(std::vector<Surface*>, int);
    bool isHit(Ray&, double, double, Record&);
    cs5721::Vector3D getNormal(cs5721::Vector3D&);
    Shader* getShader();
    cs5721::Vector3D getColor();
    Box boundingBox();
    void print();
    bool operator<(Surface*);

    struct sortX
    : std::binary_function<Surface*, Surface*, bool> {

        bool operator() (Surface* lhs, Surface * rhs)  {
            return (lhs->boundingBox().getCenter(0) < rhs->boundingBox().getCenter(0));
        }
    } sortOnX;

    struct sortY
    : std::binary_function<Surface*, Surface*, bool> {

        bool operator() (Surface* lhs, Surface * rhs) {
            return (lhs->boundingBox().getCenter(1) < rhs->boundingBox().getCenter(1));
        }
    } sortOnY;

    struct sortZ
    : std::binary_function<Surface*, Surface*, bool> {

        bool operator() (Surface* lhs, Surface * rhs)  {
            return (lhs->boundingBox().getCenter(2) < rhs->boundingBox().getCenter(2));
        }
    } sortOnZ;

};

static const int XAXIS = 0;
static const int YAXIS = 1;
static const int ZAXIS = 2;


#endif	/* BVHNODE_H */

